package com.study.util;

import java.security.MessageDigest;
import java.util.Base64;

/**
 * 加密
 * @PackgeName: com.study.util
 * @ClassName: MD5
 * @Author: 严志祥
 * Date: 2022-05-11 18:36
 * project name: web_project_medal
 * @Version:
 * @Description:
 */
public class MD5 {
    private MD5(){}
    public static String encode(String str){
        try{
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] digest = md5.digest(str.getBytes("utf-8"));
            return Base64.getEncoder().encodeToString(digest);
        }catch (Exception e){
            throw new RuntimeException("MD5加密失败",e);
        }
    }
}
